package writer_;

import org.junit.Test;

import java.io.*;

public class BuffrerdWriterCopy {
    public static void main(String[] args) {

    }
    @Test
    public void copy(){
        //用BufferedReader读文件，并用BuffferedWriter写出
        //读文件对象
        BufferedReader bufferedReader = null;
        //存独好的字符串
        String lien;
        //写文件对象
        BufferedWriter bufferedWriter=null;
        try {
            bufferedReader = new BufferedReader(new FileReader("D:\\xuexi\\str1.txt"));
            bufferedWriter=new BufferedWriter(new FileWriter("D:\\xuexi\\str2.txt",true));
            while ((lien=bufferedReader.readLine())!=null){
                bufferedWriter.write(lien);
                bufferedWriter.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
